#include <iostream>

#include <cstdlib>

#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t id = fork();
    if (id == 0)
    {
        while (true)
        {
            std::cout << "I am Child pid: " << getpid() << std::endl;
            sleep(1);
        }
        exit(0);
    }
    int state = 0;
    pid_t rid = waitpid(id, &state, 0);
    if (rid == id)
    {
        std::cout << "exit code: " << WEXITSTATUS(state) << std::endl;
        std::cout << "sign number: " << (state & 0x7F) << std::endl;
        std::cout << "core dump: " << ((state >> 7) & 0x01) << std::endl;
    }
    else
        ;

    return 0;
}